/**
 * 接口请求封装
 * 支持 get post
 */
 import axios from 'axios'
 import { Message, Loading } from 'element-ui'
 import config from './host'
 axios.defaults.baseURL = config.baseUrl
 const request = (method = '', url = '', data = {}, params) => {
   var loadingInstance = Loading.service({ fullscreen: true });
   return new Promise((resolve, reject) => {
     axios.request({
       url,
       method,
       headers: {
         'Content-Type': 'application/json; charset=UTF-8',
         'Authorization': localStorage.getItem('token')
       },
       data,
       params,
     }).then(res => {
       const { status } = res
       if (status === 200) {
         const { errCode, errMsg } = res.data
         if (errCode !== 10000) {
           Message({
             type: 'error',
             message: errMsg,
           })
         }
         resolve(res.data)
       } else {
         // 可以用switch根据code判断显示不同的信息提示
         let msg = statusCode == 404 ? '路径有误' : '信息有误'
         Message({
           type: 'error',
           message: msg,
         })
       }
       loadingInstance.close()
     }).catch(err => {
       reject(err)
       loadingInstance.close()
     })
   })
 }
 const get = (url, params) => request('GET', url, "", params)
 const post = (url, data) => request('POST', url, data, "")
 export default {
   get,
   post
 }